#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long 
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 2e6 + 10;

int n;
LL s[N];
int q[N], o[N], d[N];
bool st[N];

int main() {
	in(n);
	
	flr (i, 1, n) in(o[i]), in(d[i]), s[i] = s[i + n] = o[i] - d[i];
	flr (i, 1, n * 2) s[i] += s[i - 1];
	
	int hh = 0, tt = -1;
	frl (i, 2 * n, 1) {
	    if (hh <= tt && q[hh] >= i + n) hh ++ ;
	    while (hh <= tt && s[q[tt]] >= s[i]) tt -- ;
	    q[ ++ tt] = i;
	    if (i <= n && s[q[hh]] >= s[i - 1]) st[i] = true;
	}
	
	d[0] = d[n];
	flr (i, 1, n) s[i] = s[i + n] = o[i] - d[i - 1];
	flr (i, 1, n * 2) s[i] += s[i - 1];
	
	hh = 0, tt = -1;
	flr (i, 1, 2 * n) {
	    if (hh <= tt && q[hh] < i - n) hh ++ ;
	    if (i > n && s[q[hh]] <= s[i]) st[i - n] = true;
	    while (hh <= tt && s[q[tt]] <= s[i]) tt -- ;
	    q[ ++ tt] = i;
	}
	
	flr (i, 1, n)
	    if (st[i]) puts("TAK");
	    else puts("NIE");
	
	return 0;
} 